@extends('adminDialog')

@section('content')
    <form action="{{url('merchant/product/newj/'.$model->jobid)}}" method="POST" class="J_ajaxForm">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="pop_cont pop_table" style="overflow-y: scroll;height: 529px;">
            <table width="100%">
                <tbody>
                <tr>
                    <th><label for="title">名称 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="name" id="name" class="input length_6" value="{{$model->name}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="">显示图片</label></th>
                    <td id="tdimages">
                        <a href="javascript:;" id="pickfiles" class="pickfiles" style="float: left" title="选择上传文件">
                            <input type="hidden" name="imgurl" value="{{$model->imgurl}}"/>
                            <img src="{{url("images/defaltPic.jpg")}}"/>
                        </a>
                        @if("" != $model->imgurl)
                            @foreach(explode(',',$model->imgurl) as $img)
                                <div class="upimg">
                                    <a role="button" href="javascript:;" class="pop_close J_close" title="删除图片">删除</a>
                                    <img src="{{$img}}">
                                </div>
                            @endforeach
                        @endif
                    </td>
                </tr>
                <tr>
                    <th><label for="title">分类 <span class="red">*</span></label></th>
                    <td>
                        <select id="parentcategory" name="parentcategory">
                            <option value="">请选择</option>
                            @foreach($parents as $key=>$parent)
                                <option value="{{$key}}" {{$key == $model->parentcategory ? 'selected="selected"' : ''}}>{{$parent}}</option>
                            @endforeach
                        </select>
                        <select id="category" name="categoryid" style="display: none;">
                            @foreach($categorys as $category)
                                <option value="">请选择</option>
                                <option class="parent_{{$category->parentid}}"
                                        value="{{$category->categoryid}}" {{$category->categoryid == $model->categoryid ? 'selected="selected"' : ''}}>{{$category->name}}</option>
                            @endforeach
                        </select>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">开工时间 <span class="red">*</span></label></th>
                    <td>
                        <input type="date" name="starttime" id="starttime" class="input length_6"
                               value="{{date("Y-m-d",strtotime($model->starttime))}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">结束时间 <span class="red">*</span></label></th>
                    <td>
                        <input type="date" name="endtime" id="endtime" class="input length_6"
                               value="{{date("Y-m-d",strtotime($model->endtime))}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">期限 </label></th>
                    <td>
                        <input type="date" name="duration" id="duration" class="input length_6"
                               value="{{date("Y-m-d",strtotime($model->duration))}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">薪资 </label></th>
                    <td>
                        <input type="number" step="100" name="discount" id="discount" min="0" class="input length_2"
                               value="{{$model->discount}}"/>
                        <select name="discountunit">
                            <option {{"元/天" == $model->discountunit? "selected='selected'" : ""}}>元/天</option>
                            <option {{"元/周" == $model->discountunit? "selected='selected'" : ""}}>元/周</option>
                            <option {{"元/月" == $model->discountunit? "selected='selected'" : ""}}>元/月</option>
                            <option {{"元/小时" == $model->discountunit? "selected='selected'" : ""}}>元/小时</option>
                            <option {{"其他" == $model->discountunit? "selected='selected'" : ""}}>其他</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">地址 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="addr" id="addr" class="input length_6" value="{{$model->addr}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">工作区域 </label></th>
                    <td>
                        <input type="text" name="workarea" id="workarea" class="input length_6"
                               value="{{$model->workarea}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">数量/人数 </label></th>
                    <td>
                        <input type="number" step="1" name="workercount" id="workercount" class="input length_2" min="0"
                               value="{{$model->workercount}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">状态 </label></th>
                    <td>
                        <select name="state">
                            <option {{"未发布" == $model->state? "selected='selected'" : ""}}>未发布</option>
                            <option {{"已发布" == $model->state? "selected='selected'" : ""}}>已发布</option>
                            <option {{"抢单中" == $model->state? "selected='selected'" : ""}}>抢单中</option>
                            <option {{"已抢单" == $model->state? "selected='selected'" : ""}}>已抢单</option>
                            <option {{"进行中" == $model->state? "selected='selected'" : ""}}>进行中</option>
                            <option {{"已结束" == $model->state? "selected='selected'" : ""}}>已结束</option>
                            <option {{"已取消" == $model->state? "selected='selected'" : ""}}>进行中</option>
                            <option {{"已删除" == $model->state? "selected='selected'" : ""}}>已删除</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">工作种类 </label></th>
                    <td>
                        <select name="jobtype">
                            <option {{"长期" == $model->jobtype? "selected='selected'" : ""}}>长期</option>
                            <option {{"矩期" == $model->jobtype? "selected='selected'" : ""}}>矩期</option>
                            <option {{"兼职" == $model->jobtype? "selected='selected'" : ""}}>兼职</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th><label for="title">发布人 </label></th>
                    <td>
                        <input name="usertype" type="radio"
                               {{"个人" == $model->state? "checked='checked'" : ""}} value="个人">个人
                        <input name="usertype" type="radio"
                               {{"个人" != $model->state? "checked='checked'" : ""}} value="商家">商家
                    </td>
                </tr>
                <tr>
                    <th><label for="title">描述 <span class="red">*</span></label></th>
                    <td>
                        <textarea name="describe" style="width: 520px;height: 300px;">{{$model->describe}}</textarea>
                    </td>
                </tr>

                </tbody>
            </table>
        </div>

        <div class="pop_bottom cc">
            <button type="reset" class="btn fr" id="J_dialog_close">取消</button>
            <button type="submit" class="btn btn_submit J_ajax_submit_btn fr mr10" id="J_dialog_close">提交</button>
        </div>
    </form>
@stop

@section('style')
    <style>
        .body_none {
            width: 720px;
        }

        .upimg {
            width: 145px;
            float: left;
            margin: 0 20px;
        }

        .upimg img {
            width: 145px;
            height: 83px;
            overflow: hidden;
        }

        .upimg a {
            text-align: right;
            background: #26557F;
            display: block;
            margin: 5px;
            color: #fff;
            text-decoration: none;
            margin-top: 5px;
            float: right;
            width: 9px;
            height: 8px;
            overflow: hidden;
            text-indent: -2000em;
            background: url(/images/admin/content/close.png) no-repeat;
            -webkit-transition: all 0.2s ease-out;
            margin-left: 10px;
        }
    </style>
@stop

@section('js')
    @parent
    <script src="{{ asset('js/plupload/plupload.full.min.js') }}"></script>
    <script>
        $(function () {
            if ("请选择" != $('#parentcategory').val()) {
                $('#category').css('display', 'inherit');
                $('#category').find('option').css('display', 'none');
                $('.parent_' + $('#parentcategory').val()).css('display', 'inherit');
            } else {
                $('#category').css('display', 'none');
            }
            $('#parentcategory').change(function () {
                if ("请选择" != $('#parentcategory').val()) {
                    $('#category').css('display', 'inherit');
                    $('#category').find('option').css('display', 'none');
                    $('.parent_' + $('#parentcategory').val()).css('display', 'inherit');
                } else {
                    $('#category').css('display', 'none');
                }
            });
            $('#tdimages').on('click', '.upimg a', function () {
                $('.pickfiles input').val($('.pickfiles input').val().replace($(this).parent().find('img').attr('src'), ','));
                $(this).parent().remove();
                console.log($('.pickfiles input').val().replace($(this).parent().find('img').attr('src'), ','));
                console.log($('.pickfiles input').val().replace(',,,', ','));
                console.log($('.pickfiles input').val().replace(',,', ','));
                console.log($(this).parent().find('img').attr('src'));
            })
        });
    </script>
    <script>
        $(function () {
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'pickfiles', // you can pass in id...
                //container: document.getElementById('container'), // ... or DOM Element itself
                url: "{{ url('upimg') }}",
                filters: {
                    max_file_size: '5mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ]
                },
                multi_selection: false,
                file_data_name: 'file',
                multipart_params: {'_token': '{{ csrf_token() }}', 'dir': 'shares'},
                // Flash settings
                flash_swf_url: '{{ asset("js/plupload/Moxie.swf") }}',
                // Silverlight settings
                silverlight_xap_url: '{{ asset('js/plupload/Moxie.xap') }}',
                init: {
                    PostInit: function () {
                        return false;
                    },
                    FilesAdded: function (up, file) {
                        $('.up-pic img').attr('src', '{{ asset('images/loading.gif') }}');
                        uploader.start();
                    },
                    Error: function (up, err) {
                        tips(err.message);
                    },
                    FileUploaded: function (up, file, responseObj) {
                        var response = $.parseJSON(responseObj.response);
                        if (response.state == 'success') {
                            $('.pickfiles').parent().append('<div class="upimg"><a role="button" href="javascript:;" class="pop_close J_close" title="删除图片">删除</a><img src="{!! url("img/shares-' + response.id + '/145-83") !!}"/></div>')
                            if ("" == $('.pickfiles input').val() || "," == $('.pickfiles input').val()) {
                                $('.pickfiles input').val('{!! url("img/shares-' + response.id + '/145-83") !!}');
                            } else {
                                $('.pickfiles input').val($('.pickfiles input').val() + ',{!! url("img/shares-' + response.id + '/145-83") !!}');
                            }
                        } else {
                            tips(response.message);
                        }
                    }
                }
            });
            uploader.init();
        });
    </script>
@stop
